package com.squid.base.utils.system;

import cn.hutool.core.util.NumberUtil;
import lombok.Data;

@Data
public class Memory {
    /**
     * 内存总量
     */
    private String total;

    /**
     * 已用内存
     */
    private String used;

    /**
     * 剩余内存
     */
    private String free;
    /**
     * 使用率
     */
    private String usageRate;

    public double getTotal() {
        return NumberUtil.div(Double.parseDouble(total), (1024 * 1024 * 1024), 2);
    }

    public double getUsed() {
        return NumberUtil.div(Double.parseDouble(used), (1024 * 1024 * 1024), 2);
    }


    public double getFree() {
        return NumberUtil.div(Double.parseDouble(free), (1024 * 1024 * 1024), 2);
    }

    public double getUsage() {
        return NumberUtil.mul(NumberUtil.div(Double.parseDouble(used), Double.parseDouble(total), 4), 100);
    }
}
